package basic.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import proxy.ServiceProxy;

public abstract class BasicAction extends DispatchAction {

	protected String serviceId;

	protected ServiceProxy serviceProxy;

	public void setServiceId(String serviceId) {
		this.serviceId = serviceId;
	}

	public void setServiceProxy(ServiceProxy serviceProxy) {
		this.serviceProxy = serviceProxy;
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return executeSub(mapping, form, request, response);
	}

	public ActionForward executeSub(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String actionParameter = mapping.getParameter();
		String dispatch = request.getParameter(actionParameter);
		if (dispatch != null && !dispatch.equals(""))
			return dispatchMethod(mapping, form, request, response, dispatch);
		else
			return unspecified(mapping, form, request, response);
	}

	public ActionForward executeFatal(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return mapping.findForward("fatal");
	}

	public ActionForward unspecified(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return executeFatal(mapping, form, request, response);
	}

}
